<template>
    <div class="nav-bar">
        <!-- 左边 -->
        <!-- $router.back() -->
        <div class="left" @click="goto">
            <slot name="left"></slot>
            <!-- 使用方式 -->
            <!-- <template #left><i class="iconfont icon-zuojiantou"></i></template> -->
        </div>

        <!-- 中间 -->
        <div class="center">
            <slot></slot>
            <!-- 使用方式 -->
            <!-- <template #default>三叉戟商城</template> -->
        </div>

        <!-- 右边 -->
        <div class="right">
            <slot name="right"></slot>
            <!-- 使用方式 -->
            <!-- <template #right><i class="iconfont icon-shouye1"></i></template> -->
        </div>
    </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'

// 路由器
const router = useRouter()

const props = withDefaults(defineProps<{
    leftGotoPath?: string
}>(), {
    leftGotoPath: ''
})

// 跳转
const goto = () => {
    if (props.leftGotoPath) {
        router.push(props.leftGotoPath)
    } else {
        router.back()
    }
}
</script>

<style lang="scss">
    .nav-bar {
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #27BA9B;
        color: #FFFFFF;
        position: fixed;
        left: 0;
        right: 0;
        top: 0;
        z-index: 10;
        height: 45px;
        line-height: 45px;
        text-align: center;
        box-shadow: 0 2px 0px rgba(100, 100, 100, 0.1);
    }
    .left, .right {
        width: 80px;
    }
    .left {
        .iconfont {
            font-size: 25px;
        }
    }
    .center {
        flex: 1;
        font-size: 20px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .right {
        width: 100px;
        .iconfont {
            font-size: 25px;
        }
    }
</style>
